﻿using System;
using System.Collections.Generic;

using System.Windows.Forms;
using System.Runtime.Remoting;
using Spring.Context.Support;

using Spring.Context;
using AppToolKit.Core.Context.Spring;
using BLL;
using System.ServiceProcess;

namespace CenterDateAchieve
{
    static class Program
    {
        /// <summary>
        /// The main entry point for the application.
        /// </summary>
        [STAThread]
        static void Main()
        {
            string[] args = Environment.GetCommandLineArgs();
            if (args.Length == 2)
            {
                Exception ex;
                if ((args[1] == "-i") || (args[1] == "-I"))
                {
                    try
                    {
                        ServiceInstaller.InstallService(Application.ExecutablePath + " -d", "DataTranferService", "DataTranferService");
                        MessageBox.Show("Install Service Success");
                    }
                    catch (Exception exception1)
                    {
                        ex = exception1;
                        MessageBox.Show(string.Format("Install Service Error({0})", ex.Message));
                    }
                }
                if ((args[1] == "-u") || (args[1] == "-U"))
                {
                    try
                    {
                        ServiceInstaller.UnInstallService("DataTranferService");
                        MessageBox.Show("Uninstall Service Success");
                    }
                    catch (Exception exception2)
                    {
                        ex = exception2;
                        MessageBox.Show(string.Format("Uninstall Service Error({0})", ex.Message));
                    }
                }
                if ((args[1] == "-d") || (args[1] == "-D"))
                {
                    ServiceBase.Run(new DataTranferService());
                }
            }
            else
            {
                ContextAware contextWrapper = (ContextAware)ContextRegistry.GetContext().GetObject("ContextAwareSlot");
                AutoWiringFactory.SetContext(contextWrapper);
                Application.EnableVisualStyles();
                Application.SetCompatibleTextRenderingDefault(false);
                MainForm form = new MainForm();
                contextWrapper.AutowireObject(form);
                Application.Run(form);
            }
        }

    }
}

